<template>
  <div>
    <el-dialog :visible.sync="infocardshow" title="人员基础信息卡" width="66%">
      <el-main style="margin-top: -20px">
        <el-row>
          <el-switch
            v-model="editinfo"
            active-text="锁定"
            inactive-text="解锁"
            style="float: right"
          >
          </el-switch>
          <el-button-group>
            <el-button
              style="float: left; margin-top: -10px"
              size="small"
              type="success"
              @click="changepost = true"
              >调岗</el-button
            >

            <el-button
              style="float: left; margin-top: -10px"
              size="small"
              type="danger"
              @click="resgin = true"
              >离职访谈</el-button
            >

          </el-button-group>
        </el-row>
      </el-main>
      <work-user-info-edit
        :form="form"
        :eduexp="eduexp"
        :workexp="workexp"
        :dingtalkdeplist="dingtalkdeplist"
        :editinfo="editinfo"
        :family="family"
        :change="change"
        :type="type"
        :adminpart="adminpart"
      ></work-user-info-edit>
    </el-dialog>

    <el-dialog title="发起调岗" :visible.sync="changepost" width="40%" left>
      <el-form
        ref="form"
        :model="changepostform"
        label-width="80px"
        :rules="rules"
      >
        <!-- <el-form-item label="类型" prop="type">
          <el-select
            v-model="changepostform.type"
            placeholder="请选择"
            style="width: 100%"
          >
            <el-option
              v-for="item in typeoptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item> -->

        <el-form-item label="调出部门">
          <el-select
            v-model="form.depid"
            placeholder="请选择"
            :disabled="true"
            style="width: 100%"
          >
            <el-option
              v-for="item in selectdepartment"
              :key="item.id"
              :label="item.label"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="原职位">
          <el-input v-model="form.post" :disabled="true"></el-input>
        </el-form-item>

        <el-form-item label="调入部门" prop="depid">
          <el-select
            v-model="changepostform.depid"
            placeholder="请选择"
            style="width: 100%"
            filterable
          >
            <el-option
              v-for="item in selectdepartment"
              :key="item.id"
              :label="item.label"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="新职位" prop="post">
          <el-select
            v-model="changepostform.post"
            placeholder="请选择"
            style="width: 100%"
            filterable
          >
            <el-option
              v-for="item in selectpost"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="生效日期" prop="date">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="changepostform.date"
            style="width: 100%"
          ></el-date-picker>
        </el-form-item>

        <el-form-item label="备注">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 4 }"
            placeholder="请输入内容"
            v-model="changepostform.bz"
          >
          </el-input>
        </el-form-item>

        <el-form-item label="附件">
          <fileupload ref="fileupload"></fileupload>
        </el-form-item>

        <el-form-item>
          <el-button
            type="primary"
            @click="sendchangepost('form')"
            style="width: 48%"
            >发起流程</el-button
          >
          <el-button style="width: 48%" @click="cancelchangepost"
            >取消</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog title="离职访谈" :visible.sync="resgin" width="40%" v-if="resgin">
      <el-form>
        <el-form-item>
          <el-select
            v-model="sendtype.label"
            placeholder="请选择"
            style="width: 100%"
            @change="changeseleect($event)"
          >
            <el-option label="发送本人" value="1"></el-option>
            <el-option label="发送他人" value="2"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item v-if="sendtype.value == 2">
          <remote-select-user
            ref="rsu2"
            :rsustyles="rsustyles"
          ></remote-select-user>
        </el-form-item>

        <el-form-item v-if="sendtype.value == 1">
          <el-button
            style="width: 100%"
            type="primary"
            @click="sendresigntalkinput"
            >推送至本人钉钉</el-button
          >
        </el-form-item>

        <el-form-item v-if="sendtype.value == 2">
          <el-button style="width: 100%" type="success" @click="sendtoother"
            >推送至指定钉钉</el-button
          >
        </el-form-item>
      </el-form>
      <el-card style="margin-top: 30px"><resign-index :userid="userid" :iscomment=true></resign-index></el-card>
    </el-dialog>
  </div>
</template>

<script>
import fileupload from "../common/fileupload.vue";
import WorkUserInfoEdit from "./WorkUserInfoEdit.vue";

import RemoteSelectUser from "../common/RemoteSelectUser.vue";
import ResignIndex from "../Resign/ResignIndex.vue";

export default {
  components: { fileupload, WorkUserInfoEdit, RemoteSelectUser, ResignIndex },
  props: ["selectdepartment","adminpart"],

  created() {
    this.$bus.$on("getUserDetail", (row) => {
      this.infocardshow = true;
      this.getUserDetail(row);
    });
    this.getpost();
    // this.$refs.rsu.postvalue = this.form.userid;
  },

  data() {
    return {
      sendtype: { label: "发送本人", value: 1 },
      rsustyles: {
        width: "100%",
      },

      dingtalkdeplist: [],

      changepostform: {
        id: "",
        post: "",
        depid: "",
        type: "",
        date: "",
        bz: "",
      },
      rules: {
        post: [{ required: true, message: "请选择新职位", trigger: "change" }],
        date: [
          {
            type: "date",
            required: true,
            message: "请选择日期",
            trigger: "change",
          },
        ],
        type: [
          {
            required: true,
            message: "请选择调岗类型",
            trigger: "change",
          },
        ],
        depid: [
          {
            required: true,
            message: "请调入部门",
            trigger: "change",
          },
        ],
      },

      fileList: [],

      selectpost: [],

      changepost: false,
      resgin: false,

      infocardshow: false,
      type: 1,

      editinfo: true,
      userid:"",
      form: {},
      eduexp: [],
      workexp: [],
      family: [],
      change: [],

      eduaddcard: false,
      workaddcard: false,

      typeoptions: [
        {
          value: "0",
          label: "晋升",
        },
        {
          value: "1",
          label: "降职",
          disabled: true,
        },
        {
          value: "2",
          label: "部门变更",
        },
        {
          value: "3",
          label: "岗位变更",
        },
      ],
    };
  },

  methods: {
    sendresigninput() {},
    changeseleect(item) {
      this.sendtype.value = item;
      console.log(this.sendtype.value);
    },

    async getpost() {
      this.$axios
        .post("api/member/getpost")
        .then((response) => {
          this.selectpost = response.data;
          console.log(response);
        })

        .catch(function (error) {
          console.log(error);
        });
    },

    cancelchangepost() {
      this.$refs.fileupload.cleanfilelist();
      this.changepost = false;
      this.changepostform = {
        id: "",
        post: "",
        depid: "",
        type: "",
        date: "",
        bz: "",
      };
    },

    sendresigntalkinput() {
      this.$confirm("此操作将向用户发送离职访谈表, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let datas = {
            userid: [this.form.userid],
            postid: sessionStorage.getItem("id"),
          };
          
          this.$axios
            .post("api/resign/sendresigntalkinput", datas)
            .then((response) => {
              this.$notify({
                title: "离职访谈",
                message: "提交成功",
                type: "success",
                duration: 1500,
              });
            })
            .catch(function (error) {
              console.log(error);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },

    sendtoother() {
      this.$confirm("此操作将向用户发送离职访谈表, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let datas = {
            leaderid:this.$refs.rsu2.postvalue,
            userid: this.form.id,
            postid: sessionStorage.getItem("id"),
          };
        
          this.$axios
            .post("api/resign/sendtoother", datas)
            .then((response) => {
              this.$notify({
                title: "离职访谈",
                message: "提交成功",
                type: "success",
                duration: 1500,
              });
            })
            .catch(function (error) {
              console.log(error);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },



    sendchangepost(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let datas = {
            form: this.changepostform,
            posterid: sessionStorage.getItem("userid"),
            userid: this.form.userid,
            fileinfo: this.$refs.fileupload.fileinfo,
          };
          console.log(datas)
          this.$axios
            .post("api/member/sendchangepost", datas)
            .then((response) => {
              this.$notify({
                title: "用户信息",
                message: response.data,
                type: "success",
                duration: 1500,
              });
              this.cancelchangepost();
            })
            .catch(function (error) {
              console.log(error);
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },

    async getUserDetail(row) {
      let id = row.id;
      try {
        let res = await this.$axios.get(`api/member/getuserdetail?id=` + id);
        this.form = res.data.member[0];
        this.eduexp = res.data.eduexp;
        this.workexp = res.data.workexp;
        this.dingtalkdeplist = res.data.dingtalkdeplist;
        this.family = res.data.family;
        this.change=res.data.change;
        this.userid=res.data.member[0].id;
        console.log(res)
        // this.$refs.rsu2.postvalue
        // this.$refs.rsu.setuser(this.form.userid);
      } catch (e) {}
    },
    
  },
};
</script>

<style>
</style>